package com.ruoyi.report.controller;

import java.util.List;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.report.domain.SectorMsg;
import com.ruoyi.report.service.ISectorMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 所属行业Controller
 * 
 * @author huanshihao
 * @date 2025-02-11
 */
@RestController
@RequestMapping("/project/msg")
public class SectorMsgController extends BaseController
{
    private String prefix = "project/msg";

    @Autowired
    private ISectorMsgService sectorMsgService;

    @GetMapping()
    public String msg()
    {
        return prefix + "/msg";
    }

    /**
     * 查询所属行业列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SectorMsg sectorMsg)
    {
        startPage();
        List<SectorMsg> list = sectorMsgService.selectSectorMsgList(sectorMsg);
        return getDataTable(list);
    }

    /**
     * 导出所属行业列表
     */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SectorMsg sectorMsg)
    {
        List<SectorMsg> list = sectorMsgService.selectSectorMsgList(sectorMsg);
        ExcelUtil<SectorMsg> util = new ExcelUtil<SectorMsg>(SectorMsg.class);
        return util.exportExcel(list, "msg");
    }

    /**
     * 新增所属行业
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存所属行业
     */
    @PostMapping("/add")
    public AjaxResult addSave(@RequestBody SectorMsg sectorMsg)
    {
        return sectorMsgService.insertSectorMsg(sectorMsg);
    }

    /**
     * 修改所属行业
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SectorMsg sectorMsg = sectorMsgService.selectSectorMsgById(id);
        mmap.put("sectorMsg", sectorMsg);
        return prefix + "/edit";
    }

    /**
     * 修改保存所属行业
     */

    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SectorMsg sectorMsg)
    {
        return toAjax(sectorMsgService.updateSectorMsg(sectorMsg));
    }

    /**
     * 删除所属行业
     */

    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sectorMsgService.deleteSectorMsgByIds(ids));
    }
}
